package edu.xlh.travel.controller.admin;

import com.alibaba.fastjson.JSONArray;
import edu.xlh.travel.common.Result;
import edu.xlh.travel.pojo.Scenic;
import edu.xlh.travel.pojo.User;
import edu.xlh.travel.service.ScenicService;
import edu.xlh.travel.syslog.annontion.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.HashMap;

@Controller
@RequestMapping("/scenic")
public class ScenicController {

    @Autowired
    private ScenicService scenicService;

    /*
     * to scenic page
     * */
    @Log("跳转景点列表页面")
    @RequestMapping("/scenicList")
    public String scenicList() {
        return "admin/scenicmanage/scenicList";
    }
    /*
     *
     * findAllScenic
     * */
    @Log("查询所有的景点数据")
    @RequestMapping("/findAllScenic")
    @ResponseBody
    public Result findAllScenic(int page, int limit , HttpSession session) {
        return scenicService.findAll(page , limit , session);
    }

    /*
     * to addscenic page
     * */
    @Log("跳转景点添加页面")
    @RequestMapping("/toScenicAddPage")
    public String toScenicAddPage() {
        return "admin/scenicmanage/scenicAdd";
    }

    /*
     * edit scenic
     * */
    @Log("编辑景点")
    @RequestMapping("/edit/{id}")
    @ResponseBody
    public Result edit(@PathVariable("id")String id , @RequestBody Scenic scenic , HttpSession session) {
        return scenicService.edit(id , scenic , session);
    }

    /*
    * edit MaoShuOrComment
    * */
    @Log("编辑景点描述")
    @RequestMapping("/editMiaoShuOrComment/{id}")
    @ResponseBody
    public Result editMiaoShuOrComment(@PathVariable("id")String id , @RequestBody Scenic scenic , HttpSession session) {
        return scenicService.editMiaoShuOrComment(id , scenic , session);
    }

    /*
    * delete scenic by id
    * */
    @Log("根据id删除景点")
    @RequestMapping("/deleteById/{id}")
    @ResponseBody
    public Result deleteById(@PathVariable("id") String id , @RequestBody HashMap hashMap , HttpSession session) {
        return scenicService.deleteById(id , hashMap , session);
    }

    /*
    * add Scenic
    * */
    @Log("添加景点")
    @RequestMapping("/addScenic")
    @ResponseBody
    public Result addScenic(@RequestBody Scenic scenic , HttpSession session) {
        return scenicService.addScenic(scenic , session);
    }

    /*
     *
     * batch delete
     *  */
    @Log("批量删除景点")
    @RequestMapping("/batchDelete")
    @ResponseBody
    public Result batchDelete(@RequestBody JSONArray jsonArray , HttpSession session) {
        return scenicService.batchDelete(jsonArray ,session);
    }
    /*
     * query user by condition
     * */
    @Log("条件模糊查询景点")
    @RequestMapping("/QueryScenicByCondition")
    @ResponseBody
    public Result  QueryScenicByCondition(Integer page, Integer limit, Scenic scenic , HttpSession session) throws IOException {
        return scenicService.QueryScenicByCondition(page , limit ,scenic , session);
    }
}
